package casts.facebook
{
   import casts.step.AbstractStepContainer;
   
   import com.greensock.events.LoaderEvent;
   import com.greensock.loading.LoaderStatus;
   import com.greensock.loading.SWFLoader;
   
   import command.DoTweenMax;

   import flash.display.MovieClip;
   import flash.events.Event;

   import jp.nium.display.getInstanceById;
   import jp.progression.casts.CastMovieClip;
   import jp.progression.commands.display.AddChild;
   import jp.progression.commands.display.RemoveChild;
   
   import org.casalib.load.SwfLoad;
   
   /**
    * @author cjboy1984@gmail.com
    */
   public class fb_main extends AbstractStepContainer
   {
      // 單純就登入facebook
      private var step_0:fb_step_0 = new fb_step_0();

      public function fb_main(initObject:Object = null)
      {
         super(initObject);
         
         id = 'fb main';
         group = 'fb';
         loadingId = 'fb loading';
         
         stop();
      }
      
      // --------------------- LINE ---------------------
      
      // ################### protected ##################
      
      override protected function atCastAdded():void
      {
         // basic
         onStageResize();
         stage.addEventListener(Event.RESIZE, onStageResize);
         
         // step no
         currenStep = step_0;
         
         // animation
         addCommand(
            new AddChild(this, step_0)
         );
      }
      
      override protected function atCastRemoved():void
      {
         if (stage) stage.removeEventListener(Event.RESIZE, onStageResize);

         addCommand(
            new DoTweenMax(this, 0.4, { alpha:0, onComplete:removeAllSteps } )
         );
      }

      // --------------------- LINE ---------------------

      override protected function removeAllSteps():void
      {
         while (numChildren)
         {
            var mc:MovieClip = MovieClip(getChildAt(0));
            mc.destroy();
            removeChild(mc);
         }
      }
      
      // #################### private ###################
      
      private function onStageResize(e:Event = null)
      {
         x = orgX;
         y = orgY;
      }
      
      // Original x,y-pos
      private function get orgX():Number { return sw / 2; }
      private function get orgY():Number { return sh / 2; }
      
      private function get sw():Number { return stage.stageWidth; }
      private function get sh():Number { return stage.stageHeight; }
      
      // --------------------- LINE ---------------------
      
   }
   
}
